package com.qmx.launcher.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.open.androidtvwidget.leanback.adapter.GeneralAdapter;
import com.open.androidtvwidget.leanback.mode.OpenPresenter;
import com.qmx.launcher.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

/**
 * @author ChengXiangtong
 * @create 2018/10/27
 * @Describe
 */
public class RecyclerViewPresenter extends OpenPresenter {

    private final List<String> labels;
    private final List<String> labels_english = new ArrayList<>();
    private final List<Integer> src;
    private GeneralAdapter mAdapter;
    public Vector<Boolean> vector = new Vector<>();

    public RecyclerViewPresenter(List<String> data, List<Integer> src) {
        this.labels = data;
        this.src = src;
        labels_english.add("Dail");
        labels_english.add("Contacts");
        labels_english.add("Schedule");
        labels_english.add("Settings");
    }

    @Override
    public void setAdapter(GeneralAdapter adapter) {
        this.mAdapter = adapter;
    }

    @Override
    public int getItemCount() {
        return labels.size();
    }

    @Override
    public int getItemViewType(int position) {
        return 0;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recyclerview_view, parent, false);
        return new GridViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int position) {
        GridViewHolder gridViewHolder = (GridViewHolder) viewHolder;
        TextView textView = gridViewHolder.tv;
        ImageView image = gridViewHolder.iv;
        TextView english = gridViewHolder.text_english;
        viewHolder.view.setTag(position);
        textView.setText(labels.get(position));
        image.setImageResource(src.get(position));
        english.setText(labels_english.get(position));

        //        if (vector.get(position)) {
        //            textView.setBackgroundResource(R.color.actionbar_color);
        //        } else {
        //            textView.setBackgroundResource(R.color.item_activated_color);
        //        }
        System.err.println("onBindViewHolder===" + position);

    }

}
